package com.example.site.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.example.site.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Resource
    private UserService userService;

    /**
     * @param data
     * @return
     * @deprecated 用户登录
     */
    @PostMapping("/login")
    public SaResult login(@RequestBody Map<String, String> data) {
        return userService.login(data.get("username"), data.get("password"));
    }

    /**
     * 用户修改自己的密码
     *
     * @param data
     * @return
     */
    @SaCheckLogin
    @PostMapping("/change-password")
    public SaResult changePassword(@RequestBody Map<String, String> data) {
        return userService.changePassword(data);
    }

    /**
     * @param data
     * @return
     * @deprecated 用户修改自己的信息
     */
    @SaCheckLogin
    @PostMapping("/edit-userinfo")
    public SaResult editUserinfo(@RequestBody Map<String, String> data) {
        return userService.editUserinfo(data);
    }

    /**
     * @param data
     * @return
     * @deprecated 用户注册
     */
    @PostMapping("/sign")
    public SaResult sign(@RequestBody Map<String, String> data) {
        return userService.sign(data);
    }


}
